package data.bot;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import main.WoTCWBot;
import timertasks.BattleReminderTimerTask;
import utils.Utils;

public abstract class AbstractBattleContainer  implements Comparable<AbstractBattleContainer> 
{
	public boolean isFinal;
	public long time=0;
	public int idOfContent;
	
	public abstract String getString(StringMode sm);

	
	public List<BattleReminderTimerTask> timertasks = new ArrayList<BattleReminderTimerTask>(); 
	
	
	public enum StringMode
	{
		CombatList, BattleReminderTaskString;
	}
	
	
	public void createTimerTasks(int...b)
	{
		WoTCWBot.LOGGER.debug("creating timertasks");
		Calendar now = Calendar.getInstance();
		for(int a:b)
		{
			Calendar c = Calendar.getInstance();
			c.setTimeInMillis(time*1000);
			c.add(Calendar.MINUTE, -a);
			if(c.after(now))  //
			{
				WoTCWBot.LOGGER.trace("scheduling Reminder at "+Utils.getDateString(c.getTimeInMillis()/1000));
				BattleReminderTimerTask brtt = new BattleReminderTimerTask(this, a);
				WoTCWBot.timer.schedule(brtt,new Date(c.getTimeInMillis()));
				timertasks.add(brtt);
			}
		}
	}
	
	@Override
	public final int compareTo(AbstractBattleContainer o) {
		if(time<o.time)
		{
			return -1;
		}
		return 1;
	}
	
	public void disableTimerTasks()
	{
		for(BattleReminderTimerTask brtt: timertasks)
		{
			brtt.enabled=false;
		}
	}
	
	@Override
	public final boolean equals(Object o)
	{
		if(o instanceof AbstractBattleContainer)
		{
			AbstractBattleContainer abc = (AbstractBattleContainer)o;
			WoTCWBot.LOGGER.trace("comparing ABCs: "+time+" - "+abc.time +" and "+isFinal+" - "+abc.isFinal);
			return abc.time==time && abc.isFinal==isFinal && abc.idOfContent==idOfContent;
		}
		return false;
	}
}
